using System;
using System.IO;
using System.Collections.Generic;
using System.Text;
using System.Xml;

namespace stsdev {

  public class SolutionFileBuilder {

    public static void Create(string ProjectName, Guid ProjectGuid) {
      StreamWriter writer = new StreamWriter(ProjectName + ".sln");
      writer.WriteLine();
      if (SolutionBuilder.SolutionVersionType == SolutionVersionTypeEnum.VS2005) {
        writer.WriteLine("Microsoft Visual Studio Solution File, Format Version 9.00");
        writer.WriteLine("# Visual Studio 2005");
      }
      else {
        writer.WriteLine("Microsoft Visual Studio Solution File, Format Version 10.00");
        writer.WriteLine("# Visual Studio 2008");
      }
      
      writer.WriteLine(@"Project(""{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}"") = """ + 
                      ProjectName + @"""" + @", """ +
                      ProjectName + @".csproj"", ""{" + ProjectGuid.ToString() + @"}""");
      writer.WriteLine("EndProject");
      
      writer.WriteLine("Global");

      writer.WriteLine("  GlobalSection(SolutionConfigurationPlatforms) = preSolution");
      writer.WriteLine("    Build Solution|Any CPU = Build Solution|Any CPU");
      writer.WriteLine("    Deploy Solution|Any CPU = Deploy Solution|Any CPU");
      writer.WriteLine("    Update Solution|Any CPU = Update Solution|Any CPU");
      writer.WriteLine("    Rectract Solution|Any CPU = Rectract Solution|Any CPU");
      writer.WriteLine("    Release|Any CPU = Release|Any CPU");
      writer.WriteLine("  EndGlobalSection");

      writer.WriteLine("  GlobalSection(ProjectConfigurationPlatforms) = postSolution");

      // Add <Configurations> element for each configuation
      foreach (string Configuration in SolutionBuilder.Configurations) {
        writer.WriteLine("    {" + ProjectGuid.ToString() + @"}." + Configuration + "|Any CPU.ActiveCfg = " + Configuration + "|Any CPU");
        writer.WriteLine("    {" + ProjectGuid.ToString() + @"}." + Configuration + "|Any CPU.Build.0 = " + Configuration + "|Any CPU");
      }

      writer.WriteLine("  EndGlobalSection");
      
      writer.WriteLine("  GlobalSection(SolutionProperties) = preSolution");
      writer.WriteLine("    HideSolutionNode = TRUE");
      writer.WriteLine("  EndGlobalSection");
      writer.WriteLine("EndGlobal");

      writer.Close();

    }
  }
}
